package com.tx.collections.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 *
 */
public class LinkedBlockingQueueDemo {
    public static void main(String[] args) throws InterruptedException {
        //测试抛出异常组
//        testEx();

        //测试阻塞
//        testBlock();
        LinkedBlockingQueue queue = new LinkedBlockingQueue();
        queue.offer(1,3, TimeUnit.SECONDS);
        queue.offer(2,3, TimeUnit.SECONDS);
        queue.offer(3,3, TimeUnit.SECONDS);
        queue.offer(4,3, TimeUnit.SECONDS);
        queue.poll(3,TimeUnit.SECONDS);
        queue.poll(3,TimeUnit.SECONDS);
        queue.poll(3,TimeUnit.SECONDS);
        queue.poll(3,TimeUnit.SECONDS);
        queue.poll(3,TimeUnit.SECONDS);

    }

    private static void testBlock() throws InterruptedException {
        LinkedBlockingQueue queue = new LinkedBlockingQueue();
        queue.put("1");
        queue.take();
    }

    private static void testEx() {
        LinkedBlockingQueue queue = new LinkedBlockingQueue();
        queue.add("1");
        queue.add("2");
        queue.add("3");
        queue.remove();
        queue.remove("3");
        queue.element();
    }
}